//
//  RemarkViewController.m
//  waiMai
//
//  Created by LONG on 16/4/19.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "RemarkViewController.h"

@interface RemarkViewController ()<UITextViewDelegate>

@end

@implementation RemarkViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationItem.title = @"填写备注";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"arrow"] style:UIBarButtonItemStylePlain target:self action:@selector(back)];
    [self.navigationItem.leftBarButtonItem setTintColor:[UIColor whiteColor]];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"确定" style:UIBarButtonItemStylePlain target:self action:@selector(getMessage)] ;
    [self.navigationItem.rightBarButtonItem setTintColor:UIColorFromRGB(0xffffff)];
    _textView.text = self.str;
    _textView.delegate = self;
    _textView.returnKeyType = UIReturnKeyDone;
    
    UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(backClick)];
    [self.view addGestureRecognizer:tgr];

}
- (void)backClick{
    [_textView resignFirstResponder];

}
- (IBAction)comBut:(UIButton *)sender {
    switch (sender.tag) {
            
        case 50:{
            NSRange range = [_textView.text rangeOfString:@"请提供餐具"];
            if (range.length == 0) {
                _textView.text = [_textView.text stringByAppendingString:@" 请提供餐具"];
            }
            break;
        }
        case 51:{
            _textView.text = [_textView.text stringByReplacingOccurrencesOfString:@"辣一点" withString:@"不吃辣"];
            NSRange range = [_textView.text rangeOfString:@"不吃辣"];
            if (range.length == 0) {
                _textView.text = [_textView.text stringByAppendingString:@" 不吃辣"];
            }
            break;
        }
        case 52:{
            _textView.text = [_textView.text stringByReplacingOccurrencesOfString:@"不吃辣" withString:@"辣一点"];
            NSRange range = [_textView.text rangeOfString:@"辣一点"];
            if (range.length == 0) {
                _textView.text = [_textView.text stringByAppendingString:@" 辣一点"];
            }
            break;
        }
        case 53:{
            NSRange range = [_textView.text rangeOfString:@"米饭多一点"];
            if (range.length == 0) {
                _textView.text = [_textView.text stringByAppendingString:@" 米饭多一点"];
            }
            break;
        }
        case 54:{
            NSRange range = [_textView.text rangeOfString:@"不要香菜"];
            if (range.length == 0) {
                _textView.text = [_textView.text stringByAppendingString:@" 不要香菜"];
            }
            break;
        }
        default:
            break;
    }
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    
    if ([text isEqualToString:@"\n"]){
        [self getMessage];
        return NO;
    }
    return YES;
}

- (void)getMessage{
    if (_block) {
        _block(_textView.text);
    }
    [self.navigationController popViewControllerAnimated:YES];

}
-(void)back{
    [self.navigationController popViewControllerAnimated:YES];
}

@end
